{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name '2708'
test("2708 (random_chance)", tests)
terminate_this_custom_script


function tests
    it("should always be true", test1)
    it("should always be false", test2)
    it("should produce correct chance", test3)
    return
    
    function test1
        int i
        float count
    
        count = 0.0
        for i = 1 to 100
            if
                random_chance {percent} 100.0
            then
                count += 1.0
            end
        end
        assert_eqf(count, 100.0)
        
        count = 0.0
        for i = 1 to 100
            if
                random_chance {percent} 200.0
            then
                count += 1.0
            end
        end
        assert_eqf(count, 100.0)
    end
    
    function test2
        int i
        float count
    
        count = 0.0
        for i = 1 to 100
            if
                random_chance {percent} 0.0
            then
                count += 1.0
            end
        end
        assert_eqf(count, 0.0)
        
        count = 0.0
        for i = 1 to 100
            if
                random_chance {percent} -10.0
            then
                count += 1.0
            end
        end
        assert_eqf(count, 0.0)
    end
    
    function test3
        float count = 0.0
    
        int i
        for i = 1 to 500
            if
                random_chance {percent} 33.33333
            then
                count += 1.0
            end
        end
        count /= 500.0
    
        assert_rangef(count, 0.2, 0.4) // expected value 0.333(3)
    end
end
